<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            *{
                margin: 0px;
                padding: 0px;
                list-style: none;
            }
            textarea{
                width:600px;
                margin: 10px auto;
                display: block;
                resize: none;
                outline: none;
            }
            button{
                width:600px;
                margin: 10px auto;
                display: block;
                cursor: pointer;
            }
            span{
                cursor: pointer;
            }
            ul{
                width:600px;
                margin: 10px auto;
                display: none;
            }
            ul>li{
                margin-bottom: 10px;
                position: relative;
                padding: 4px;
                background-color: black;
                color: white;
            }
            span{
                position: absolute;
                right:0px;
                top:-3px;
                cursor: pointer;
                color: white;
            }
            .x{
                display: block;
            }
        </style>
    </head>
    <body>
        <textarea name="" id="txt" cols="30" rows="10"></textarea>
        <button id="btn">发布</button>
        <ul id="box">
            <li>
                <p>2021-1-1</p>
                <span onclick="del(this)">X</span>
            </li>
        </ul>
        <script >
            var x=document.getElementsByClassName('x');
            btn.onclick=function(){
                if(txt.value==''){
                    alert('请输入内容');
                }else{
                    var val=txt.value;
                    var tag=document.createElement('li');
                    tag.innerHTML=` ${val}
                    <span  onclick="del(this)">X</span>`
                    box.appendChild(tag);
                    txt.value='';
                    box.className='x';
                    
                }
            }
            function del(a){
                a.parentNode.parentNode.removeChild(a.parentNode)
            }
        </script>
    </body>
</html>